package netty.nio;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;

/**
 * @Author: zhangrongqing
 * @Date: 2020/1/7 18:48
 */
public class SocketChannelClientDemo {
    public static void main(String[] args) throws Exception{
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.configureBlocking(false);
        if(!socketChannel.connect(new InetSocketAddress("127.0.0.1",9090))){
            while (!socketChannel.finishConnect()){

            }
            System.out.println("连接成功");
        }

//        Selector selector = Selector.open();
//        socketChannel.register(socketChannel

        String str = "hello,world";
        ByteBuffer byteBuffer = ByteBuffer.wrap(str.getBytes());

        socketChannel.write(byteBuffer);
        System.in.read();
        socketChannel.close();
    }
}
